#include "CImage.h"
#include "CVector.h"
#include <string>

CImage::CImage(std::string path, int frameCountX, int frameCountY) :
	image(VGCDisplay::openImage(path, frameCountX, frameCountY)),
	frameCountX(frameCountX),
	frameCountY(frameCountY),
	ready(true) {
	this->imageWidth	= VGCDisplay::getWidth(this->image);
	this->imageHeight	= VGCDisplay::getHeight(this->image);
	this->frameWidth	= this->imageWidth / frameCountX;
	this->frameHeight	= this->imageHeight / frameCountY;
}

CImage::~CImage() {
	if (ready) {
		VGCDisplay::closeImage(image);
	}
}

VGCImage CImage::getImage() {
	return this->image;
}

int CImage::getWidth() {
	return this->imageWidth;
}

int CImage::getHeight() {
	return this->imageHeight;
}

int CImage::getFrameWidth() {
	return this->frameWidth;
}

int CImage::getFrameHeight() {
	return this->frameHeight;
}

int CImage::getFrameCountX() {
	return this->frameCountX;
}

int CImage::getFrameCountY() {
	return this->frameCountY;
}

void CImage::drawFrame(VGCVector frameIndex, CVector position, VGCAdjustment frameAdjustment) {
	VGCDisplay::renderImage(getImage(), frameIndex, position.toVGC(), frameAdjustment);
}

void CImage::destroy() {
	VGCDisplay::closeImage(getImage());
}